package com.wmssystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wmssystem.dto.Result;
import com.wmssystem.entity.MaterialDetailMaintenance;
import com.wmssystem.entity.OuterDetail;
import com.wmssystem.service.impl.OuterDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("outerDetail")
@ResponseBody
public class OuterDetailController {
    @Autowired
    OuterDetailService outerDetailService;

    @PostMapping("increase")
    public Result increase(@RequestBody OuterDetail outerDetail) {
        log.info(outerDetail.toString());
        outerDetail.setStatus("未接收");
        outerDetailService.save(outerDetail);
        return Result.ok("添加成功");
    }

    @PostMapping("update")
    public Result update(@RequestBody OuterDetail outerDetail) {
        outerDetailService.updateById(outerDetail);
        return Result.ok("更新成功");
    }

    @DeleteMapping("delete")
    public Result delete(Long outerDetailId) {
        outerDetailService.removeById(outerDetailId);
        return Result.ok("删除成功");
    }

    @GetMapping("query")
    public Result query(@RequestParam(value = "page", defaultValue = "1") Integer page,
                        @RequestParam(value = "size", defaultValue = "10") Integer size) {
        Page<OuterDetail> Page = new Page<>(page,size);
        outerDetailService.page(Page, new QueryWrapper<OuterDetail>().orderByAsc("outer_detail_id"));
        List<OuterDetail> outerDetails = Page.getRecords();
        return Result.ok(outerDetails);
    }
}
